// JavaScript Document

$(document).ready(function () {
	$("#home").click(function() { 
		clickHome(this);
		myScroll.scrollToPage(0, 0);
	});
	$("#about").click(function() {
		clickorder(this);
		myScroll.scrollToPage(1, 0);
	});
	$("#portfolio").click(function() { 
		clickperson(this);
		myScroll.scrollToPage(2, 0);
	});
	$("#contact").click(function() { 
		//$(window).scrollTop(0,0);
		clickmore(this);
		myScroll.scrollToPage(3, 0);
	});
});
//页面加载方法
function loadImages() {
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById('hidepage').style.visibility = 'hidden';
    } else {
        if (document.layers) { // Netscape 4
            document.hidepage.visibility = 'hidden';
        } else { // IE 4
            document.all.hidepage.style.visibility = 'hidden';
        }
    }
   /* var zcwx=$.session.get("zcwx");
    alert(zcwx);
    if(zcwx!=1){
    	location.href = "web2zc/returnMsg.jsp?errorMsg=请在手机微信中打开"
		//layer.open({content: '请先注册！',time: 2,end: function(){location.href = "../returnMsg.jsp?isapp=0"}});
	}*/
}
//侧滑和菜单点击前要处理事件的方法
function pevMenuChange (){
	$("body").animate({scrollTop: '0px'},500); 
	$("body").scrollTop(0);
	var menu=$('#navigation').find('a').eq(myScroll.currPageX);
	menuname=$(menu).attr('id');
	if("home"!=menuname){
		$(".dmore").remove();
		var allPage=$("#expand-all").attr("allPage");
		$("#expand-all").attr("curPage",1);
		if(allPage>1){
			$("#expand-all").show();
			$(".area-loading").hide();
		}
	}
}

function changMenu(){
	var menu=$('#navigation').find('a').eq(myScroll.currPageX);
	menuname=$(menu).attr('id');
	if("home"==menuname){
		clickHome(menu);
	}else if("about"==menuname){
		clickorder(menu);
	}else if("portfolio"==menuname){
		clickperson(menu);
	}else if("contact"==menuname){
		clickmore(menu);
	}else{
		clickHome(menu);
	}
	
}

function clickHome(menu){
	$(menu).addClass('selected').find("img").attr("src","images/nav/item1zc_pre.png");
	$(menu).parent().parent().find('#about, #portfolio, #contact').removeClass('selected');
	$(menu).parent().parent().find(".about").hide().find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().find("#about").find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().parent().find(".portfolio").hide().find("img").attr("src","images/nav/item3ns.png");
	$(menu).parent().find("#portfolio").find("img").attr("src","images/nav/item3ns.png");
	$(menu).parent().parent().find(".contact").hide().find("img").attr("src","images/nav/item4ns.png");
	$(menu).parent().find("#contact").find("img").attr("src","images/nav/item4ns.png");
	$(".title").html("今日早餐");
}
function clickorder(menu){
	$(menu).addClass('selected').find("img").attr("src","images/nav/item2ns_pre.png");
	$(menu).parent().parent().find('#home, #portfolio, #contact').removeClass('selected');
	$(menu).parent().parent().find(".home").hide().find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().find("#home").find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().parent().find(".portfolio").hide().find("img").attr("src","images/nav/item3ns.png");
	$(menu).parent().find("#portfolio").find("img").attr("src","images/nav/item3ns.png");
	$(menu).parent().parent().find(".contact").hide().find("img").attr("src","images/nav/item4ns.png");
	$(menu).parent().find("#contact").find("img").attr("src","images/nav/item4ns.png");
	$(".title").html("订单查询");
	
}
function clickperson(menu){
	$(menu).addClass('selected').find("img").attr("src","images/nav/item3ns_pre.png");
	$(menu).parent().parent().find('#home, #about, #contact').removeClass('selected');
	$(menu).parent().parent().find(".home").hide().find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().find("#home").find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().parent().find(".about").hide().find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().find("#about").find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().parent().find(".contact").hide().find("img").attr("src","images/nav/item4ns.png");
	$(menu).parent().find("#contact").find("img").attr("src","images/nav/item4ns.png");
	$(".title").html("个人中心");
}
function clickmore(menu){
	$(menu).addClass('selected').find("img").attr("src","images/nav/item4ns_pre.png");
	$(menu).parent().parent().find('#home, #about, #portfolio').removeClass('selected');
	$(menu).parent().parent().find(".home").hide().hide().find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().find("#home").find("img").attr("src","images/nav/item1zc.png");
	$(menu).parent().parent().find(".about").hide().find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().find("#about").find("img").attr("src","images/nav/item2ns.png");
	$(menu).parent().parent().find(".portfolio").hide().find("img").attr("src","images/nav/item3ns.png");
	$(menu).parent().find("#portfolio").find("img").attr("src","images/nav/item3ns.png");
	$(".title").html("更多功能");
}

//格式化时间
function formatDate(timestamp){
	var str = "";
	var date = new Date(timestamp);
	str = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	return str;
}

//检测手机号码格式
function validateMobileNum(mobileNum){
	var re = /^[1][34578]\d{9}$/;
	if(!re.test(mobileNum)){
		return false;
	}else{
		return true;
	}
}

//检测充值金额正整数
function validateMoney(Money){
	var re =/^[0-9]*[1-9][0-9]*$/;
	return re.test(Money);
}

//对Date的扩展，将 Date 转化为指定格式的String 
//月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
//年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
//例子： 
//(new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
//(new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function(fmt) 
	{ //author: meizz 
	var o = { 
	 "M+" : this.getMonth()+1,                 //月份 
	 "d+" : this.getDate(),                    //日 
	 "h+" : this.getHours(),                   //小时 
	 "m+" : this.getMinutes(),                 //分 
	 "s+" : this.getSeconds(),                 //秒 
	 "q+" : Math.floor((this.getMonth()+3)/3), //季度 
	 "S"  : this.getMilliseconds()             //毫秒 
	}; 
	if(/(y+)/.test(fmt)) 
	 fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	for(var k in o) 
	 if(new RegExp("("+ k +")").test(fmt)) 
	fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 
	return fmt; 
}; 



function choice(obj){
    var radioId = $(obj).attr('name');
    $('label').attr('class','lnotchecked') && $(obj).attr('class', 'lchecked');
    $('input[type="radio"]').removeAttr('checked') && $('#' + radioId).attr('checked', 'checked');	 
}


function choiceMoreImage(obj){
	if(obj=='1'){
		$("#moreBtns").html("<div class='more_btns'>"+
				"<img  src='images/more/more_11.png' onclick='choiceMoreImage(1)'>"+
				"<img  src='images/more/more_02.png' onclick='choiceMoreImage(2)'>"+
			"</div>"+
			"<div class='more_btns'>"+
				"<img  src='images/more/more_03.png' onclick='choiceMoreImage(3)'>"+
				"<img  src='images/more/more_04.png' onclick='choiceMoreImage(4)'>"+
			"</div>");
	}else if(obj=='2'){
		$("#moreBtns").html("<div class='more_btns'>"+
				"<img  src='images/more/more_01.png' onclick='choiceMoreImage(1)'>"+
				"<img  src='images/more/more_12.png' onclick='choiceMoreImage(2)'>"+
			"</div>"+
			"<div class='more_btns'>"+
				"<img  src='images/more/more_03.png' onclick='choiceMoreImage(3)'>"+
				"<img  src='images/more/more_04.png' onclick='choiceMoreImage(4)'>"+
			"</div>");
	}else if(obj=='3'){
		$("#moreBtns").html("<div class='more_btns'>"+
				"<img  src='images/more/more_01.png' onclick='choiceMoreImage(1)'>"+
				"<img  src='images/more/more_02.png' onclick='choiceMoreImage(2)'>"+
			"</div>"+
			"<div class='more_btns'>"+
				"<img  src='images/more/more_13.png' onclick='choiceMoreImage(3)'>"+
				"<img  src='images/more/more_04.png' onclick='choiceMoreImage(4)'>"+
			"</div>");
	}else if(obj=='4'){
		$("#moreBtns").html("<div class='more_btns'>"+
				"<img  src='images/more/more_01.png' onclick='choiceMoreImage(1)'>"+
				"<img  src='images/more/more_02.png' onclick='choiceMoreImage(2)'>"+
			"</div>"+
			"<div class='more_btns'>"+
				"<img  src='images/more/more_03.png' onclick='choiceMoreImage(3)'>"+
				"<img  src='images/more/more_14.png' onclick='choiceMoreImage(4)'>"+
			"</div>");
	}
	$(".morePI").addClass("hide");
	$('#more'+obj).removeClass("hide");
}


//============================早餐配送区域页 start===================================

//加载早餐配送区域页
function loadHome(){
	 var url="transaction2zcRouter?funcID=0001";
	 $.ajax({  
        type : "post",  
        url : url,  
        async: false,  
        success : function(v){
       	 flag=v.responseCode;
       	 if(flag=="00000"){
       		 var total=v.page.total;
       		 if(total!=0){
       			 var curpage=v.page.curpage;
        		 var allPage=v.page.allPage;
        		 var list=v.page.list;
        		 $.each(list,function(){
        			 $(".clearfix").append("<a class='district-list-item' href='transaction2zcRouter?funcID=0011&landmarkId="+this.id+"'>"+this.area+"</a>");
        		 })
        		if(curpage==allPage){
        			$("#expand-all").hide();
        		}else{
        			$("#expand-all").show();
        		}
        		$("#expand-all").attr("curPage",curpage);
        		$("#expand-all").attr("allPage",allPage);
       		 }else{
       			 $(".clearfix").append("<a class='district-list-item' href='transaction2zcRouter?funcID=0011&landmarkId=1'>环球广场</a>"); 
       			 $("#expand-all").hide();
       		 }
       		
       	 }else{
       		location.replace("web2zc/returnMsg.jsp?errorMsg=服务器繁忙");
       		//layer.open({content: '服务器繁忙！',time: 2});  
       	 }
        } ,error: function(v){  
        	location.replace("web2zc/returnMsg.jsp?errorMsg=服务器繁忙");
        	//layer.open({content: '服务器繁忙！',time: 2});  
        }
	});
}

//展开更多的早餐配送区域
function expand(obj){
	var curPage=$(obj).attr("curPage");
	var params="curPage="+((curPage-0)+1);
	var url="transaction2zcRouter?funcID=0001";
	$(".area-loading").show(); 
	$(obj).hide();
	 $.ajax({  
       type : "post",  
       url : url,  
       data : params,
       /*async: false,  */
       success : function(v){
      	 flag=v.responseCode;
      	 if(flag=="00000"){
  			 var curpage=v.page.curpage;
        		 var allPage=v.page.allPage;
        		 var list=v.page.list;
        		 $.each(list,function(){
        			 $(".clearfix").append("<a class='district-list-item dmore' href='transaction2zcRouter?funcID=0011&landmarkId="+this.id+"'>"+this.area+"</a>");
        		 })
        		if(curpage==allPage){
        			$(obj).hide();
        			$(".area-loading").hide(); 
        		}else{
        			$(obj).show();
        			$(".area-loading").hide(); 
        		}
        		$("obj").attr("curPage",curpage);
      	 }else{
      		layer.open({content: '服务器繁忙！',time: 2});
      		$(obj).show();
      		$(".area-loading").hide(); 
      	 }
       },error: function(v){
      	  layer.open({content: '服务器繁忙！',time: 2});
      	  $(obj).show();
      	  $(".area-loading").hide(); 
       }
	 });
}

//============================早餐配送区域页 end===================================

//============================早餐订单页 start===================================
//加载订单查询
function loadOrder(curPage){
	 var url="transaction2zcRouter?funcID=0002";
	 $.ajax({  
        type : "get",  
        url : url,  
        async: false,  
        success : function(v){
        	if(v.responseCode=="00000"){
				if(v.list.length!=0){
					if(curPage=="")curPage=1;
					if(curPage=="last")curPage=v.list.length;
					laypage({
						cont: 'orderPage',
						pages: v.list.length,
						curr: curPage,
						first: false,
						last: false,
					    //prev: false,
					    //next: false,
					    groups: 1,
					    skin: '#ff6c0d',
					    jump: function(e){
					    	var url = "web2zc/order/orderAjax.jsp?";
					        var i = e.curr-1;
					        var o = v.list[i];
							var createTime = new Date(o.createTime);
							var remark=o.remark;
							if(remark==null){
								remark="";
							}
							url += "orderNum="+o.orderNum+"&createTime="+createTime.Format("yyyy-MM-dd hh:mm:ss")
								+"&status="+o.status+"&itemSize="+o.itemSize+"&total="+o.total
								+"&payStatus="+o.payStatus+"&curPage="+e.curr+"&userMp="+o.userMp+"&remark="+encodeURIComponent(remark);
							$.post(url, function(data) {
								$("#order").show();
								$(".order_table").html(data);
							});
							if(o.payStatus==1){
								$("#pay").addClass("hide");
							}else{
								$("#pay").removeClass("hide");
							}
					     }
					});
				}else{
					$("#order").show();
					$("#order").load("web2zc/order/orderNoAjax.jsp?title=您还没相关订单");
				}
        	}else{
        		$("#order").show();
				$("#order").load("web2zc/order/orderNoAjax.jsp?title=订单加载异常");
        	}
        },error: function(v){
        	  //layer.open({content: '服务器繁忙！',time: 2});
        	$("#order").show();
			$("#order").load("web2zc/order/orderNoAjax.jsp?title=订单加载异常");
        }
	 });
}
function payOrder(){
	var orderNum=$("#orderNum").html();
	var total=$("#total").html();;
	var curPage=$("#curPage").val();
	var userMp=$("#userMp").val();
	//alert(orderNum+","+total);
	wxPay(orderNum,total,curPage,userMp);
}
function  loadOrderCompleted(){
	 $.ajax({  
        type : "get",  
        url : "../../transaction2zcRouter?funcID=0003",  
        success : function(v){
        	if(v.responseCode=="00000"){
        		var list=v.page.list;
				if(list.length!=0){
					$.each(list,function(){
						var mtime = new Date(this.endTime);
						var status=this.status;
						var str="完成时间";
						if(status=='2'){
							str="取消时间";
						}
						$("#orderCompleted").append(
						"<div class='order_completed'>"+
						"<div class='order_completed_content'>"+
							"<div>"+
								"<div class='order_completed_title'><p>订&nbsp;&nbsp;单&nbsp;&nbsp;号:</p></div>"+
								"<div class='order_completed_data'><p>"+this.orderNum+"</p></div>"+
							"</div>"+
							"<div>"+
								"<div class='order_completed_title'><p>"+str+":</p></div>"+
								"<div class='order_completed_data'><p style='color: #787878'>"+mtime.Format("yy-MM-dd hh:mm:ss")+"</p></div>"+
							"</div>"+
							"<div>"+
								"<div class='order_completed_title'><p>订单明细:</p></div>"+
								"<div class='order_completed_data'><p>共<font color='#ffc60d'>"+this.itemSize+"</font>件&nbsp;&nbsp;总计:<font color='#ffc60d'>"+this.total+"</font>元</p></div>"+
							"</div>"+
						"</div>"+
						"<div class='order_completed_btn'>"+
							"<span></span>"+
							"<a href='../../transaction2zcRouter?funcID=0022&orderNum="+this.orderNum+"&curPage=0' >"+
								"<img src='../../images/order/detail_service.png'>"+
							"</a>"+
						"</div>"+
					"</div>");
					});
					var curpage=v.page.curpage;
	        		var allPage=v.page.allPage;
					if(curpage==allPage){
	        			$("#expand-all").hide();
	        		}else{
	        			$("#expand-all").show();
	        		}
	        		$("#expand-all").attr("curPage",curpage);
	        		$("#expand-all").attr("allPage",allPage);
				}else{
					$("#otitle").html("您还没有相关的订单！");
					$("#order").show();
				}
        	}else{
        		$("#otitle").html("订单加载异常！");
        		$("#order").show();
        	}
        },error: function(v){
        	$("#otitle").html("订单加载异常！");
        	$("#order").show();
        }
	 });
}
//加载更多完成订单
function  orderMore(obj){
	 var curPage=$(obj).attr("curPage");
	 var params="curPage="+((curPage-0)+1);
	 $(".area-loading").show(); 
	 $(obj).hide();
	 $.ajax({  
	        type : "post",  
	        url : "../../transaction2zcRouter?funcID=0003",
	        data:params,
	        success : function(v){
	        	if(v.responseCode=="00000"){
	        		var list=v.page.list;
					$.each(list,function(){
						var mtime = new Date(this.endTime);
						var status=this.status;
						var str="完成时间";
						if(status=='2'){
							str="取消时间";
						}
						$("#orderCompleted").append(
						"<div class='order_completed'>"+
						"<div class='order_completed_content'>"+
							"<div>"+
								"<div class='order_completed_title'><p>订&nbsp;&nbsp;单&nbsp;&nbsp;号:</p></div>"+
								"<div class='order_completed_data'><p>"+this.orderNum+"</p></div>"+
							"</div>"+
							"<div>"+
								"<div class='order_completed_title'><p>"+str+":</p></div>"+
								"<div class='order_completed_data'><p style='color: #787878'>"+mtime.Format("yy-MM-dd hh:mm:ss")+"</p></div>"+
							"</div>"+
							"<div>"+
								"<div class='order_completed_title'><p>订单明细:</p></div>"+
								"<div class='order_completed_data'><p>共<font color='#ffc60d'>"+this.itemSize+"</font>件&nbsp;&nbsp;总计:<font color='#ffc60d'>"+this.total+"</font>元</p></div>"+
							"</div>"+
						"</div>"+
						"<div class='order_completed_btn'>"+
							"<span></span>"+
							"<a href='../../transaction2zcRouter?funcID=0022&orderNum="+this.orderNum+"&curPage=0' >"+
								"<img src='../../images/order/detail_service.png'>"+
							"</a>"+
						"</div>"+
					"</div>");
					});
					var curpage=v.page.curpage;
	        		var allPage=v.page.allPage;
	        		if(curpage==allPage){
	        			$(obj).hide();
	        			$(".area-loading").hide(); 
	        		}else{
	        			$(obj).show();
	        			$(".area-loading").hide(); 
	        		}
	        		$("obj").attr("curPage",curpage);
	        	}else{
	        		layer.open({content: '服务器繁忙！',time: 2});
	        		$(obj).show();
	          		$(".area-loading").hide(); 
	        	}
	        },error: function(v){
	        	layer.open({content: '服务器繁忙！',time: 2}); 
	        	$(obj).show();
	      		$(".area-loading").hide(); 
	        }
		 });
}
//查询订单日志
function zcOrserLog(orderNum){
 $.ajax({  
   type : "get",  
   url : "../../transaction2zcRouter?funcID=0021&orderNum="+orderNum,  
   success : function(v){
	   if(v.responseCode=="00000"){
   			var str = "";
   			var length = v.list.length;
   			for(var i=0;i<length-1;i++){
   				var temp = v.list[i];
   				var date = new Date(temp.logTime);
   				str = "<div class='track_hit'><div class='track_img'><img  src='../../images/order/technological_process.png'></div><div class='track_content'><p>"+temp.log+"</p><p>"+date.Format("yyyy-MM-dd hh:mm:ss")+"</p></div></div>";
   				$("hr").after(str);
   			}
   			var date = new Date(v.list[length-1].logTime);
   			str = "<div class='track_now'><div class='track_img'><img  src='../../images/order/current_position.png'></div><div class='track_content'><p>"+v.list[length-1].log+"</p><p>"+date.Format("yyyy-MM-dd hh:mm:ss")+"</p></div></div>";
   			$("hr").after(str);
   			$(".track").find("font").html(orderNum);
   		 }else{
   			location.replace("../returnMsg.jsp?errorMsg=服务器繁忙");
   			 //layer.open({content: '服务器繁忙！',time: 2});
   			 //history.back(-1);
   		 }
   },error: function(v){
	   location.replace("../returnMsg.jsp?errorMsg=服务器繁忙");
  	  //layer.open({content: '服务器繁忙！',time: 2});
  	  //history.back(-1);
   }
 });
}

//============================早餐订单页 end===================================

//============================早餐下单页 start===================================

//选择的商品减1
function jian(moeny,obj){
	var number=$(obj).next().find('p').text()-0;
	if(number>0){
		$(obj).next().find('p').text(number-1);
		var cnumber=$("#cnumber").text()-0;
		var cprice=$("#cprice").text()-0;
		if(cnumber>0){
			$("#cnumber").text(cnumber-1)-0;
		}
		if(cprice>0){
			$("#cprice").text(cprice-(moeny-0));
		}
	}
	
}
//选择的商品加1
function jia(moeny,obj){
	/*var id=$(obj).prev().attr('class');
	alert(id);*/
	var number=$(obj).prev().find('p').text()-0;
	$(obj).prev().find('p').text(number+1);
	var cnumber=$("#cnumber").text()-0;
	var cprice=$("#cprice").text()-0;
	$("#cnumber").text(cnumber+1);
	$("#cprice").text(cprice+(moeny-0));
}

//选择的商品减1
function jian(obj){
	var moeny=$(obj).next().find('p').attr("price")-0;
	var number=$(obj).next().find('p').text()-0;
	if(number>0){
		$(obj).next().find('p').text(number-1);
		var cnumber=$("#cnumber").text()-0;
		var cprice=$("#cprice").text()-0;
		if(cnumber>0){
			$("#cnumber").text(cnumber-1)-0;
		}
		if(cprice>0){
			$("#cprice").text(cprice-(moeny-0));
		}
	}
	
}
//选择的商品加1
function jia(obj){
	/*var id=$(obj).prev().attr('class');
	alert(id);*/
	var moeny=$(obj).prev().find('p').attr("price")-0;
	var number=$(obj).prev().find('p').text()-0;
	$(obj).prev().find('p').text(number+1);
	var cnumber=$("#cnumber").text()-0;
	var cprice=$("#cprice").text()-0;
	$("#cnumber").text(cnumber+1);
	$("#cprice").text(cprice+(moeny-0));
}

//获取早餐订单的json对象
function zcOrderJO(userName,userMp,size,total,aid,areaId,area,address,remark,list){
	var o=new Object();
	o.userName=userName;
	o.userMp=userMp;
	o.itemSize=size;
	o.total=total;
	o.aid=aid;
	o.userAreaId=areaId;
	o.userArea=area
	o.userAddress=address;
	o.remark=remark;
	o.list=list;
	return o;
}
//获取早餐json对象
function zcItemJO(id,name,price,week,sellTime,sellCount,url){
	var zi=new Object();
	zi.id=id;
	zi.name=name;
	zi.price=price;
	zi.week=week;
	zi.sellTime=sellTime;
	zi.sellCount=sellCount;
	zi.url=url;
	return zi;
}
function postJsondata(){
	var size=$("#cnumber").html()-0;
	if(size!=0){
		var total=$("#cprice").html();
		var areaId=$("#areaId").val();
		var area=$("#area").val();
		var address="";
		var list=new Array(); 
		$.each($(".zcItem"),function(){
			var sell=$(this).attr("sell");
			if(sell=="true"){
				var sellCount=$(this).find("#zcCount").html()-0;
				if(sellCount>0){
					var id=$(this).attr("zcid");
					var name=$(this).find("#pzcName").html();
					var price=$(this).find("#pzcPrice").html();
					var week=$(this).find("#week").attr("week");
					var sellTime=$(this).find(".dataNum").html();
					var url=($(this).find("#expand-all").attr("switchWeek")-0)+1;
					list.push(zcItemJO(id,name,price,week,sellTime,sellCount,url));
				}
			}
		});
		//alert(JSON.stringify(zcOrderJO(size,total,areaId,address,list)));
		$("#orderJson").val(JSON.stringify(zcOrderJO("","",size,total,"",areaId,area,address,"",list)));
		$("#zcItemFrom").submit();
	}else{
		 layer.open({content: '请选择早餐套餐！',time: 2}); 
	}

}

//============================早餐下单页  end===================================




//============================早餐订单详情 start===================================

function orderExpand(){
	 $(".zcmore").toggle(1000);
	 var imgClass=$(".arrow-down").attr("class");
	 if(imgClass=="arrow-down"){
		 $(".arrow-down").addClass("flip"); 
		 
	 }else{
		 $(".arrow-down").removeClass("flip");
	 }
}

function placeOrder(){
	var url="transaction2zcRouter?funcID=0013";
	var userName=$("#userName").val();
	var userMp=$("#userMp").val();
	var userAddress=$("#userAddress").val();
	if(userName==""){
		 layer.open({content: '请输入姓名！',time: 2}); 
		 return;
	}
	if(userMp==""){
		 layer.open({content: '请输入手机号！',time: 2});
		 return;
	}
	if(!validateMobileNum(userMp)){
		layer.open({content: '手机号码格式错误！',time: 2}); 
		return;
	}
	if(userAddress==""){
		 layer.open({content: '请输取餐地址！',time: 2});
		 return;
	}
	var size=$("#cnumber").html()-0;
	var total=$("#cprice").html();
	var aid=$("#areaInfo").attr("aid");
	var areaId=$("#areaInfo").attr("areaId");
	var area=$("#areaInfo").val();
	var address=$("#userAddress").val();
	var sendTime=$("#sendTime").val();
	var remark=$("#remark").val();
	var list=new Array(); 
	$.each($(".zcItem"),function(){
			var sellCount=$(this).find("#zcCount").html()-0;
			var id=$(this).attr("zcid");
			var name=$(this).find("#pzcName").html();
			var price=$(this).find("#pzcPrice").html();
			var week=$(this).find("#week").attr("week");
			var sellTime=$(this).find("#dataNum").html()+sendTime;
			var url=$(this).find(".zcImg").attr("src");
			list.push(zcItemJO(id,name,price,week,sellTime,sellCount,url));
	});
	var fistDateArray=$(".zcItem").find("#dataNum").html().split("/");
	var fistDateStr=fistDateArray[0]+"月"+fistDateArray[1]+"日";
	//alert(JSON.stringify(zcOrderJO(userName,userMp,size,total,areaId,address,list)));
	var params="orderJson="+JSON.stringify(zcOrderJO(userName,userMp,size,total,aid,areaId,area,address,remark,list));
	params=params.replace(/\+/g, "%2B");//"+"转义
	layer.open({
	    content: '您的早餐将于<font color=red>'+fistDateStr+'</font>开始配送,<br>请及时支付。',
	    btn: ['<font color=red>知道了，去支付</font>', '取消'],
	    yes: function(index){
	        $.ajax({  
	            type : "post",  
	            url : url,  
	            data : params,
	            success : function(v){
	           	 if(v.responseCode=="00000"){
	           		//调用支付接口
	           		wxPay(v.orderNum,v.total,"last",userMp);
	           		//layer.open({content: '下单成功',time: 2});
	           		//location.replace("index2zc.jsp?toPage=1&curPage=last");
	           	 }else{
	           		layer.open({content: '服务器繁忙！',time: 2}); 
	           	 }
	            },error: function(v){  
	           	 layer.open({content: '服务器繁忙！',time: 2}); 
	            }
	     	});
	        layer.close(index);
	    }
	});
	
}



//============================早餐订单详情 end===================================


//============================早餐订单支付页面 start===================================

//选择支付方式
function choicePay(obj){
	var array = $(".choicePay");
	$.each(array, function(key, value){
		$(value).find("td:eq(2)").removeClass().addClass("pay_null").html("<img src='../../images/person/null.png'>");
	});
	$(obj).find("td:eq(2)").removeClass().addClass("pay_select").html("<img src='../../images/person/choice.png'>");
}

//微信支付
var outTradeNo,curPage;
function wxPay(orderNum,total,curP,userMp){
	var url="transaction2zcRouter";
	//var params="funcID=0017&out_trade_no=${param.orderNum}&body=JRZC&total_fee=${param.price}&curPage=${param.curPage}&openid="+$.session.get('platformId');
	var params="funcID=0017&out_trade_no="+orderNum+"&body=JRZC&total_fee="+total+"&curPage="+curP+"&userMp="+userMp;
	//alert(params);
	$.ajax({  
    	type : "post",  
        url : url,  
        data : params,
        dataType:'xml',
        success : function(xml){ 
        //这些可以在后头封装好了----这样太乱
        //alert(xml);
    	var return_code = $(xml).find("return_code").text();
		if(return_code=="SUCCESS"){
			var resultCode = $(xml).find("result_code").text();
			if(resultCode=="SUCCESS"){
				outTradeNo = $(xml).find("out_trade_no").text();
				curPage = $(xml).find("curPage").text();
				var appId = $(xml).find("appId").text();
				var timeStamp = $(xml).find("timeStamp").text();
				var pack = $(xml).find("package").text();
				var nonceStr = $(xml).find("nonce_str").text();
				var signType = $(xml).find("signType").text();
				var paySign =$(xml).find("paySign").text();
				//alert("appId="+appId.substr(9,36)+"&timeStamp="+timeStamp+"&nonceStr="+nonceStr+"&pack="+pack+"&signType="+signType+"&paySign="+paySign);
				if (typeof WeixinJSBridge == "undefined"){
			    	if( document.addEventListener ){
						document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
					}else if (document.attachEvent){
					    document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
					    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
					}
				}else{
			    	onBridgeReady(appId,timeStamp,nonceStr,pack,signType,paySign);
				}
			}else{
				var errCodeDes=$(xml).find("err_code_des").text();
				layer.open({content: errCodeDes,time: 2});
			}
		}else{
			var returnMsg=$(xml).find("return_msg").text();
			layer.open({content: returnMsg,time: 2});
		}
     },error: function(v){  
        	layer.open({content: '服务器繁忙11！',time: 2});
     }
  }); 
}
//微信html5 js调用接口
function onBridgeReady(appId,timeStamp,nonceStr,pack,signType,paySign){
	//alert("11111appId="+appId+"&timeStamp="+timeStamp+"&nonceStr="+nonceStr+"&pack="+pack+"&signType="+signType+"&paySign="+paySign);
  	WeixinJSBridge.invoke(
       'getBrandWCPayRequest', {
           "appId" : appId,     //公众号名称，由商户传入     
           "timeStamp": timeStamp,         //时间戳，自1970年以来的秒数     
           "nonceStr" : nonceStr, //随机串     
           "package" : pack,     
           "signType" : signType,         //微信签名方式:     
           "paySign" : paySign //微信签名 
    },
    function(res){  
    	// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。 
    	var url="transaction2zcRouter?funcID=0018&toPage=1&curPage="+curPage+"&out_trade_no="+outTradeNo;
        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
        	//alert(url);
        	layer.open({content: '支付成功',time: 2,end: function(){location.href =url;}});
        }else{
        	layer.open({
        	    content: '今日早餐感谢您的支持。',
        	    btn: ['已支付', '<font color=red>重新支付</font>'],
        	    yes: function(index){
        	    	location.replace("index2zc.jsp?toPage=1&curPage="+curPage);
        	        layer.close(index);
        	    }
        	});
        }   
    }
   ); 
}

//============================早餐订单支付页面 end===================================


//============================早餐地址相关方法 start======================================

function choiceaddr(obj){
	$('.choiceimg').attr('src','images/person/no_choice.png');
	$('.addrbox').removeAttr("style");
	$('.addrbox').removeClass("addrboxCheck");
	$(obj).find("img").first().attr('src','images/person/choice.png');
	$(obj).css('background-color',' #7ecef4');
	$(obj).addClass("addrboxCheck");
}

//============================早餐地址相关方法 end======================================







